using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for DesignerLogEntryAdaptor.
	/// </summary>
	public class DesignerLogEntryAdaptor : Adaptor, IDeletable
	{
    private DesignerLogEntry entry;
		public DesignerLogEntryAdaptor(DesignerLogEntry entry)
		{
      this.entry = entry;
		}

    public override int ImageIndex
    {
      get
      {
        const string userError = "%User.Error";
        // change icon depending on source
        if (entry.Source == "Authentication")
          return 0;
        else if (entry.Source == "Designer")
          return 12;
        else if (entry.Details.IndexOf(userError) > -1)
          return 34;
        else
          return 15;
      }
    }

    public override Control GetRenderer()
    {
      DesignerLogEntryControl logEntryControl = new DesignerLogEntryControl();
      logEntryControl.LoadEntry(entry);
      logEntryControl.ItemDeleted += new EventHandler(TriggerItemDeleted);
      return logEntryControl;
    }

    public override string Text
    {
      get
      {
        return entry.Description;
      }
    }

    public override object Object
    {
      get
      {
        return entry;
      }
    }

    #region IDeletable Members

    public void Delete()
    {
      entry.Delete();
    }

    #endregion
  }
}
